<?php

namespace app\admin\service;

use app\common\model\MoneyLog;
use app\common\model\ScoreLog;
use think\Model;

class StaticService
{
    //获取PV
    public function getPv($group_id = '',$short_chain_id,$date_start,$date_end){
        $redis = new \Redis();
        $redis->connect('127.0.0.1', 6379);
        $redis->select(1);
        $date_range = printDates($date_start,$date_end);
        $pv = 0;
        $uv = 0;
        $ip = 0;
        foreach($date_range as $k=>$v){
            if($group_id){
                $pv += $redis->get('short_chain_times_id_group_'.$v.'_'.$short_chain_id);
                $uv += $redis->sCard('short_chain_user_cookie_group_'.$v.'_'.$short_chain_id);
                $ip += $redis->sCard('short_chain_ip_ip_group_'.$v.'_'.$short_chain_id);
            }else{
                $pv += $redis->get('short_chain_times_id_'.$v.'_'.$short_chain_id);                     //short_chain_times_id_2023-01-15_132
                $uv += $redis->sCard('short_chain_user_cookie_'.$v.'_'.$short_chain_id);
                $ip += $redis->sCard('short_chain_ip_ip_'.$v.'_'.$short_chain_id);
            }
        }
        return [
            'pv'=>$pv,
            'uv'=>$uv,
            'ip'=>$ip,
        ];
    }
    //获取UV
    public function getUv($group_id = '',$short_chain_id,$date_start,$date_end){

    }
    //获取IP
    public function getIp($group_id = '',$short_chain_id,$date_start,$date_end){

    }

}
